package cn.com.my.yes1;

import java.util.Calendar;
import java.util.Date;


/**
 * 通信加密解析
 * @author chenhs
 * @time 2016年1月4日 下午8:34:34
 */
public class DayTest2 {

	public static void main(String[] args) {

	//    findSixMonthsAmount();
		String pmac = "e10adc3949ba59abbe56e057f20f883e";
		String timeStamp = "1451958406193";
	//	String hmac = "6150147a023f94cc 473b3c43 7c68fc6ae1e1eb39";		//16 + 8 + 16
		String hmac = "7279ea80681e4011bc80b5b2f5b2aa200b7cd51e";   
		String imei = "";
		
		
		Date d = new Date();
	//	timeStamp = d.getTime() + "";
		System.out.println("timeStamp: " + timeStamp);//时间戳　
		
		String temp = MD5Util.toMd5(timeStamp.getBytes());//时间戳的md5值
		String ts = temp.substring(temp.length() - 8, temp.length());//时间戳md5结果值后８位即，ts的后８个字符
		String tmp = ts;
		
		System.out.println("ts: " + ts);//md5(timeStamp).substring(len-8, len)
		System.out.println("tmp: " + tmp);//md5(timeStamp)
		
		String mix = MD5Util.toMd5(pmac.concat(ts).getBytes());
		System.out.println("mix: " + mix);//md5(pmac + ts)
		
		String prefix = mix.substring(0, 2*8);//前16位字符
		String suffix = mix.substring(2*8+1, mix.length());//后15位字符，总长是32位的md5
		
		
		System.out.println("pre: " + prefix);
		System.out.println("suf: " + suffix);
		
		System.out.println(hmac.startsWith(prefix));
		System.out.println(hmac.endsWith(suffix));
		System.out.println(hmac.substring(2 * 8, hmac.length() - 2 * 8).equals("bc80b5b2"));
	}
	
/*	
	private boolean checkPrefix() {
		return hmac.startsWith(prefix);
	}

	private boolean checkSuffix() {
		return hmac.endsWith(suffix);
	}
	
	private boolean checkMiddle() {
		return hmac.substring(2 * 8,
				hmac.length() - 2 * 8).equals(getTmp());
	}
	*/
	
	
	
	/**
	 * 最近６个的拥金
	 */
	public static void findSixMonthsAmount(){
		for(int i=0; i<6; i++){
			Calendar cal = Calendar.getInstance();
			cal.add(Calendar.MONTH, -i);
		    int year = cal.get(Calendar.YEAR);
			int month = cal.get(Calendar.MONTH) + 1;
			
			String mn = month<10?(year +"0"+ month):year +""+ month;
			System.out.println(mn);
		}
	}
}
